﻿#include "FuncEvent.h"
#include<QApplication>
FuncEvent::FuncEvent(std::function<bool()> fun)
	:QEvent(QEvent::Type(ET_FuncEvent)),
	m_fun(fun)
{
}
FuncEvent::FuncEvent(QObject* receiver, std::function<bool()> fun)
	:QEvent(QEvent::Type(ET_FuncEvent)),
	m_fun(fun)
{
	QApplication::postEvent(receiver, this);
}
void FuncEvent::postEvent(QObject* receiver,int priority)
{
	QApplication::postEvent(receiver, this, priority);
}
FuncEventFilter::FuncEventFilter(QObject* parent)
    :EventFilter([=](QEvent* ev)->bool {
    auto func = static_cast<FuncEvent*>(ev);
    return func->m_fun();    //返回true表示此事件已经处理了，不会继续传播
        }, EventType::ET_FuncEvent,parent)
{

}